home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
admin.xul
< prev
next >
Wrap
Extensible Markup Language
|
2009-12-16
|
10KB
|
333 lines
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload = "init();"
>
<script>
<![CDATA[
const CI = Components.interfaces;
const CL = Components.classes;
Components.utils.import("resource://yoono/yoonoService.js");
Components.utils.import("resource://yoono/yoonoKeyValueDB.js");
var timerSearchKey = null;
var FFPath = '';
var IEPath = '';
var IEDir = '';
var IEKeyFile = null;
var target = 'FF';
var IEList = {};
var keys = {};
function init() {
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get('ProfDS', Components.interfaces.nsIFile);
FFPath = file.path;
var labelProf = document.getElementById('profile');
var textNode = document.createTextNode(FFPath);
labelProf.appendChild(textNode);
labelProf.setAttribute('style', '-moz-user-select:text;-moz-user-focus:normal');
IEPath = FFPath;
var mark = IEPath.indexOf('AppData');
if( mark != -1) {
IEPath = IEPath.substring(0, mark) + 'AppData\\LocalLow\\Yoono\\keyvalues';
} else {
mark = IEPath.indexOf('Application Data');
IEPath = IEPath.substring(0, mark) + 'Application Data\\Yoono\\keyvalues';
}
IEDir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
IEDir.initWithPath(IEPath);
IEKeyFile = IEDir.clone();
IEKeyFile.append('keys.txt');
if(!IEKeyFile.exists()) {
document.getElementById('selectBrowser').setAttribute('collapsed', 'true');
}
searchKeys();
}
function searchKeys() {
if(timerSearchKey) {
clearTimeout(timerSearchKey);
}
timerSearchKey = setTimeout(function() {doSearchKeys()}, 200);
}
function doSearchKeys() {
document.getElementById('key').focus();
var key = document.getElementById('key').value;
var value = '';
var row = null;
var label = null;
var labelText = null;
var delButton = null;
var editButton = null;
var text = '';
var width = 100;
var rows = document.getElementById('rows');
while(rows.lastChild != rows.firstChild) {
rows.removeChild(rows.lastChild);
}
var tab = getKeyValueList(key);
tab.sort(function(a, b) {
if(a.key == b.key) return(0);
if(a.key < b.key) return(-1);
else return(1);
});
for(var i=0; i < tab.length; i++ ) {
key = tab[i].key;
value = tab[i].value;
label = document.createElement('label');
//label.setAttribute('value', key);
labelText = document.createTextNode(key);
label.appendChild(labelText);
label.setAttribute('style', 'padding-top:5px;-moz-user-select:text;-moz-user-focus:normal');
row = document.createElement('row');
row.appendChild(label);
delButton = document.createElement('button');
delButton.setAttribute('label', 'Del');
delButton.setAttribute('key', key);
delButton.setAttribute('onclick', 'deleteKey(this)');
row.appendChild(delButton);
editButton = document.createElement('button');
editButton.setAttribute('label', 'Edit');
editButton.setAttribute('key', key);
editButton.setAttribute('onclick', 'editValue(this)');
row.setAttribute('style', 'border-bottom: 1px solid lightGrey');
row.appendChild(editButton);
label = document.createElement('textbox');
label.setAttribute('size', width);
label.setAttribute('width', "700px");
if(value.length > width) {
var nb = Math.floor(value.length / width);
if(nb > 10) nb = 10;
label.setAttribute('multiline', 'true');
label.setAttribute('rows', nb + 2);
}
label.setAttribute('readonly', 'true');
label.setAttribute('id', key);
label.setAttribute('value', value);
row.appendChild(label);
rows.appendChild(row);
}
}
function deleteKey(button) {
var key = button.getAttribute('key');
var conf = confirm('Erase ' + key + ' ? ' );
if(conf) {
deleteKeyValue(key);
}
doSearchKeys();
}
function editValue(button) {
var key = button.getAttribute('key');
var valueElt = document.getElementById(key);
var readOnly = valueElt.getAttribute('readonly') || 'false' ;
if('false' == readOnly) {
var value = valueElt.value;
setKeyValue(key, value);
valueElt.setAttribute('readonly', 'true');
button.setAttribute('label', 'Edit');
doSearchKeys();
} else {
valueElt.removeAttribute('readonly');
button.setAttribute('label', 'Save');
}
}
function getKeyValueList(pattern) {
var tab = new Array();
if('FF' == target) {
if(pattern) pattern = '%' + pattern; // trailing % is implemented in YOONO_KEYVALUEDB.getKeyValueList
var liste = YOONO_KEYVALUEDB.getKeyValueList(pattern);
for(var key in liste) {
tab.push({'key' : key, 'value' : liste[key]});
}
return(tab);
}
var result = {};
var istream = CL["@mozilla.org/network/file-input-stream;1"].createInstance(CI.nsIFileInputStream);
istream.init(IEKeyFile, 0x01, 0444, 0);
istream.QueryInterface(CI.nsILineInputStream);
IEList = {};
var line = {};
var hasmorelines;
pattern = pattern.toLowerCase();
do {
hasmorelines = istream.readLine(line);
var equalPosition = line.value.indexOf('=');
if(-1 != equalPosition) {
var key = line.value.substring(0, equalPosition);
var fileName = line.value.substring(equalPosition + 1);
IEList[key] = fileName;
if(-1 != key.toLowerCase().indexOf(pattern)) {
var value = readFile(fileName);
tab.push({'key' : key, 'value' : value});
}
}
} while(hasmorelines);
istream.close();
return(tab);
}
function deleteKeyValue(key) {
if('FF' == target) {
return YOONO_KEYVALUEDB.deleteKeyValue(key);
}
// get value file name
var valueFileName = IEList[key];
// WARNING. IE does not read the key file again...
// remove key from list
delete(IEList[key]);
// write updated file
var outputStream = CL["@mozilla.org/network/file-output-stream;1"].createInstance( CI.nsIFileOutputStream);
var converter = CL['@mozilla.org/intl/converter-output-stream;1'].createInstance(CI.nsIConverterOutputStream);
converter.init(outputStream, 'UTF-8', 1024, '-');
// RW, CREATE_FILE, TRUNCATE
// from http://lxr.mozilla.org/aviary101branch/source/nsprpub/pr/include/prio.h
outputStream.init(IEKeyFile, 0x04 | 0x08 | 0x20 , 0644, 0);
for(var key in IEList) {
converter.writeString(key + '=' + IEList[key] + "\r\n");
}
converter.flush();
outputStream.flush();
outputStream.close();
// remove matching value file
var valueFile = IEDir.clone();
valueFile.append(valueFileName);
valueFile.remove(false);
// and re create it empty
valueFile.create(0, 4);
}
function setKeyValue(key, value) {
if('FF' == target) {
return YOONO_KEYVALUEDB.setKeyValue(key, value);
}
var outputFileName = IEList[key];
var outputFile = IEDir.clone();
outputFile.append(outputFileName);
// write updated file
var outputStream = CL["@mozilla.org/network/file-output-stream;1"].createInstance( CI.nsIFileOutputStream);
var converter = CL['@mozilla.org/intl/converter-output-stream;1'].createInstance(CI.nsIConverterOutputStream);
converter.init(outputStream, 'UTF-8', 1024, '-');
// RW, CREATE_FILE, TRUNCATE
// from http://lxr.mozilla.org/aviary101branch/source/nsprpub/pr/include/prio.h
outputStream.init(outputFile, 0x04 | 0x08 | 0x20 , 0644, 0);
converter.writeString(value);
converter.flush();
outputStream.flush();
outputStream.close();
}
function readFile(fileName) {
var result = '';
try {
var oneFile = IEDir.clone();
oneFile.append(fileName);
var istream = CL["@mozilla.org/network/file-input-stream;1"].createInstance(CI.nsIFileInputStream);
istream.init(oneFile, 0x01, 0444, 0);
var converter = CL["@mozilla.org/intl/converter-input-stream;1"].createInstance( CI.nsIConverterInputStream);
converter.init(istream, 'UTF-8', 1024, '-');
var line = {};
while(converter.readString(4096, line)) {
result+=line.value;
}
istream.close();
} catch(e) {
//alert('File ' + fileName + ' is missing');
}
return(result);
}
function saveNewKey() {
if('FF' != target) {
alert('Not yet available with IE');
}
var newKey = document.getElementById('newKey');
var newValue = document.getElementById('newValue');
setKeyValue(newKey.value, newValue.value);
searchKeys();
newKey.value = '';
newValue.value = '';
}
function setTarget(selector) {
target = selector.value ;
if('FF' == target) {
document.getElementById('profile').firstChild.textContent = FFPath;
} else {
document.getElementById('profile').firstChild.textContent = IEPath;
}
searchKeys();
}
function aboutYoono() {
document.location = "about:yoono";
}
]]>
</script>
<radiogroup id="selectBrowser">
<radio label="Firefox" selected="true" value="FF" onclick="setTarget(this)"/>
<radio label="Internet Explorer" value="IE" onclick="setTarget(this)"/>
</radiogroup>
<hbox>
<label value="Profile directory : "/>
<label id="profile" />
</hbox>
<spacer height="20px"/>
<hbox align="center">
<label value="Key Filter: "/>
<textbox onkeyup="searchKeys()" id="key"/>
<button label="Remove" oncommand="this.previousSibling.value=''; searchKeys()"/>
<button label="Refresh" oncommand="searchKeys()"/>
<spacer flex="1"/>
<button label="About Yoono" oncommand="aboutYoono()"/>
</hbox>
<hbox align="center">
<label value="Create new Key: "/>
<textbox size="40" id="newKey" value="" tabindex="1"/>
<label value="Value: "/>
<textbox size="60" id="newValue" value="" tabindex="2"/>
<button label="Save" onclick="saveNewKey()" tabindex="3"/>
</hbox>
<vbox style="overflow:auto" flex="1">
<grid>
<columns>
<column/>
<column/>
<column/>
<column/>
</columns>
<rows id="rows">
<row align="center" flex="1" style="border: 1px solid black">
<label value="Key Name"/>
<box/>
<box/>
<label value="Value"/>
</row>
</rows>
</grid>
</vbox>
</window>